package org.example.ioc;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class IocConfig {

    @Bean("serviceA1")
    public ServiceA serviceA1() {
        log.info("create serviceA1");
        // 同一个类下可以直接调用创建 Bean 的方法，多次调用仅创建一次
        return new ServiceA(serviceB2());
    }

    @Bean("serviceA2")
    public ServiceA serviceA2() {
        log.info("create serviceA2");
        // 同一个类下可以直接调用创建 Bean 的方法，多次调用仅创建一次
        return new ServiceA(serviceB2());
    }

    @Bean("serviceB1")
    public ServiceB serviceB1() {
        log.info("create serviceB1");
        return new ServiceB();
    }

    @Bean("serviceB2")
    public ServiceB serviceB2() {
        log.info("create serviceB2");
        return new ServiceB();
    }

}
